
let userId_const = localStorage.getItem("userId");
let userName_const = localStorage.getItem("userName");

let username = $(".dropdown-user-name");
username.find('i').remove();
let user_name = '<i>你好，'+userName_const+'老师</i>';
username.append(user_name);                       //生成导航栏的老师名字
username = $("#user_name");
username.find('span').remove();
user_name = '<span>'+userName_const+'老师</span>'      //生成导航栏下拉框的老师名字
username.append(user_name);

$(document).ready(function() {
            $.ajax({
                url: '/user/findByUserId_A',
                type: 'get',
                dataType: 'json',
                async:false,
                data:{"userId":userId_const},
                success: function (data) {
                    console.log(data);



                    let tr;
                    let tr1;
                    let tr2;
                    let tr3;

                    tr  = '<div id="1" class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户ID" + '</div>' + '<div id="5" class="user-info-margin text-center text-bold ">:</div>' + '<div id="9"class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userId + '</div>' ;
                    tr1 = '<div id="2" class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户名" + '</div>' + '<div id="6"class="user-info-margin text-center text-bold ">:</div>' + '<div id="10"class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userName + '</div>' ;
                    tr2 = '<div id="3" class="col-2 alert-primary text-center text-bold user-info-margin">' + "邮箱地址" + '</div>' + '<div id="7"class="user-info-margin text-center text-bold ">:</div>' + '<div id="11"class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userEmail + '</div>' ;
                    tr3 = '<div id="4" class="col-2 alert-primary text-center text-bold user-info-margin">' + "个人简介" + '</div>' + '<div id="8"class="user-info-margin text-center text-bold ">:</div>' + '<div id="12"class="col-2 alert-info text-bold  user-info-margin">' + data[0].userBrief + '</div>' ;

                    $("#information").append(tr);
                    $("#information1").append(tr1);
                    $("#information2").append(tr2);
                    $("#information3").append(tr3);
                }
            });

            $("#modify").click(function (){
                let obj = document.getElementById('1');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('2');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('3');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('4');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('5');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('6');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('7');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('8');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('9');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('10');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('11');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('12');
                obj.parentNode.removeChild(obj);
                $.ajax({
                    url: '/user/findByUserId_A',
                    type: 'get',
                    dataType: 'json',
                    async:false,
                    data:{"userId":userId_const},
                    success: function (data) {
                        let tr;

                        let tr1;
                        let tr2;
                        let tr3;
                        tr  = '<div id="1" class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户ID" + '</div>' + '<div id="5" class="user-info-margin text-center text-bold ">:</div>' + '<div id="9"class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userId + '</div>' ;
                        tr1 = '<div id="2" class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户名" + '</div>' + '<div id="6"class="user-info-margin text-center text-bold ">:</div>' + '<div id="10"class="col-2 alert-info text-bold text-center user-info-margin"><input id="13" type="text" class="form-control form-control-success" value=" ' + data[0].userName + ' "/></div>' ;
                        tr2 = '<div id="3" class="col-2 alert-primary text-center text-bold user-info-margin">' + "邮箱地址" + '</div>' + '<div id="7"class="user-info-margin text-center text-bold ">:</div>' + '<div id="11"class="col-2 alert-info text-bold text-center user-info-margin"><input id="14" type="email" placeholder="Email Address" class="form-control form-control-success" value=" ' + data[0].userEmail + ' "/></div>' ;
                        tr3 = '<div id="4" class="col-2 alert-primary text-center text-bold user-info-margin">' + "个人简介" + '</div>' + '<div id="8"class="user-info-margin text-center text-bold ">:</div>' + '<div id="12"class="col-2 alert-info text-bold  user-info-margin"><textarea  id="15"  style="width: 205px; height: 250px;">' +data[0].userBrief + '</textarea></div>' ;

                        // tr = '<div class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户ID" + '</div>' + '<div class="user-info-margin text-center text-bold ">:</div>' + '<div class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userId + '</div>' ;
                        // tr1 = '<div class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户名" + '</div>' + '<div class="user-info-margin text-center text-bold ">:</div>' + '<div class="col-2 alert-info text-bold text-center user-info-margin"><input type="text" value=" ' + data[0].userName + ' "/></div>' ;
                        // tr2 = '<div class="col-2 alert-primary text-center text-bold user-info-margin">' + "邮箱地址" + '</div>' + '<div class="user-info-margin text-center text-bold ">:</div>' + '<div class="col-2 alert-info text-bold text-center user-info-margin"><input type="text" type="email" value=" ' + data[0].userEmail + ' "/></div>' ;
                        // tr3 = '<div class="col-2 alert-primary text-center text-bold user-info-margin">' + "个人简介" + '</div>' + '<div class="user-info-margin text-center text-bold ">:</div>' + '<div class="col-2 alert-info text-bold text-center user-info-margin"><input type="text" value=" ' +data[0].userBrief + ' "/></div>' ;
                        $("#information").append(tr);
                        $("#information1").append(tr1);
                        $("#information2").append(tr2);
                        $("#information3").append(tr3);


                    }
                });
            })
    $("#save").click(function (){
        let userName =  $("#13").val();
        let userEmail = $("#14").val();
        let userBrief = $("#15").val();
        console.log(userName);
        console.log(userEmail);
        console.log(userBrief);

        $.ajax({
            url: '/user/upDateUserInformation',
            type: 'get',
            dataType: 'json',
            async:false,
            data:{"userId":userId_const,"userName":userName,"userEmail":userEmail,"userBrief":userBrief},
            success:function (){
                swal({title:"用户信息修改成功！",type:"success"});
                $.ajax({
                    url: '/user/findByUserId_A',
                    type: 'get',
                    dataType: 'json',
                    async:false,
                    data:{"userId":userId_const},
                    success:function (data){
                        localStorage.setItem('userName',data[0].userName);
                        let username = $(".dropdown-user-name");
                        username.find('i').remove();
                        let user_name = '<i>你好，'+data[0].userName+'老师</i>';
                        console.log(user_name);
                        username.append(user_name);                       //生成导航栏的老师名字
                        username = $("#user_name");
                        username.find('span').remove();
                        user_name = '<span>'+data[0].userName+'老师</span>'      //生成导航栏下拉框的老师名字
                        username.append(user_name);
                    }
                })
                let obj = document.getElementById('1');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('2');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('3');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('4');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('5');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('6');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('7');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('8');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('9');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('10');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('11');
                obj.parentNode.removeChild(obj);
                obj = document.getElementById('12');
                obj.parentNode.removeChild(obj);
                $.ajax({
                    url: '/user/findByUserId_A',
                    type: 'get',
                    dataType: 'json',
                    async:false,
                    data:{"userId":userId_const},
                    success: function (data) {
                        let tr;
                        let tr1;
                        let tr2;
                        let tr3;

                        tr = '<div id="1" class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户ID" + '</div>' + '<div id="5" class="user-info-margin text-center text-bold ">:</div>' + '<div id="9"class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userId + '</div>';
                        tr1 = '<div id="2" class="col-2 alert-primary text-center text-bold user-info-margin">' + "用户名" + '</div>' + '<div id="6"class="user-info-margin text-center text-bold ">:</div>' + '<div id="10"class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userName + '</div>';
                        tr2 = '<div id="3" class="col-2 alert-primary text-center text-bold user-info-margin">' + "邮箱地址" + '</div>' + '<div id="7"class="user-info-margin text-center text-bold ">:</div>' + '<div id="11"class="col-2 alert-info text-bold text-center user-info-margin">' + data[0].userEmail + '</div>';
                        tr3 = '<div id="4" class="col-2 alert-primary text-center text-bold user-info-margin">' + "个人简介" + '</div>' + '<div id="8"class="user-info-margin text-center text-bold ">:</div>' + '<div id="12"class="col-2 alert-info text-bold  user-info-margin">' + data[0].userBrief + '</div>';

                        $("#information").append(tr);
                        $("#information1").append(tr1);
                        $("#information2").append(tr2);
                        $("#information3").append(tr3);
                    }
            })

            }

        });

    })








})
